/*
************************************************************************************************************************
*                                                   GLOBLE
*                                               (c) Copyright 2013; 
*                           All rights reserved.  Protected by international copyright laws.
*
*filename     : globle.h
*brief        : This file is used to define or declare globle varibles,defines,functions,which service for common access.
*programmer(s): 
*version      : V0.00
*update       : 2013-05-17
************************************************************************************************************************
* Note(s) : (1) none.
************************************************************************************************************************
*/

#ifndef _APP_GLOBLE_H_
#define _APP_GLOBLE_H_

#include "gd32f30x.h"
#include "commInterface.h"

#define ID_BASE  0x1FFFF7E8

/*
************************************************************************************************************************
*                                           globle defines
************************************************************************************************************************
*/

#define        SET_IO_PIN_OF_LED                 GPIO_SetBits(GPIOA,GPIO_Pin_15)
#define        CLR_IO_PIN_OF_LED                 GPIO_ResetBits(GPIOA,GPIO_Pin_15)
#define        TOG_IO_PIN_OF_LED                 GPIO_ToggleBits(GPIOA,GPIO_Pin_15)

typedef  void (*pFunction)(void);

#define APPLICATION_ADDRESS                      (uint32_t)0x08004000      /* firmware code start here in system flash*/
#define FIRMWARE_UPGRADE_BASE                    (FLASH_ADDR_BLOCK_1)      /* firmware code stored here in SPI Flash  */


typedef struct
{
    T32U progsn;
    T32U timvalid;		/* flag */
    T32U progbeg;		/* ts */
    T32U progend;		/* ts */
}PROGTIM;

typedef struct
{
  T08U start_valid;
  T08U nouse0;  
  T08U nouse1;
  T08U nouse2;
}START;
typedef struct
{
    T32U     progvalid;		/* 1 is valid,any else is unvalid */
    START    special;
    T32U     prognum;
//    T32U     progaddr[PROG_MAX + 2];/* the last two addr is START prog & URGENT prog */
    T32U     progtimnum;
 //   PROGTIM  t[TIM_PROG_MAX];
//    T08U     untimed[PROG_MAX]; /* must be 4byte aligned  */
 //   GLED     screen;
    T32U     color;
    T32U     scanway;
    T32U     OE;
    T32U     DA;
    T32U     ScreenModuleSize;
    T32U     rownumof1road;
    T32U     scannum;
    T32U     swapRG;
    T32U     scan_no_138;		/* flag to tell scan type,have no 74HC138 chips */
    T08U     scantable[0x100];
    T32U     bright;
    T32U     setbright1;
    T32U     setbright2;
    T32U     setbright3;
    T32U     bright123;		/* valid or not */
    T32U     setonoff1;
    T32U     setonoff2;
    T32U     setonoff3;
    T32U     onoff123;		/* valid or not */
    T32U     language;
    T32U     license;
    T32U     wordlibvalid;/* chinese word library valid library.bit0:16*16CN,bit1:16*8EN bit2:32*32CN bit3:32*16EN bit4:48*48CN,bit5:48*48EN*/
    T32U     DispDataBase;   /* address of "DISPLAY DATA" in using now,must be one of BaseA and BaseB  */
    T32U     crc;	  /* WARNING:::the CRC must be the last element!!!! */
}SCREENCFG;

typedef struct{
    T32U     chipstatus;	/* 0:everyting is ok,1,spiflash error */
    T32U     sysstatus;	/* 0:everyting is ok,bit0 set:ledctrlTask is del */
    T32U     uniqueid;
    T32U     testkey;
    T32U     block;
    T32U     TempDispDataBase;
    T32U     wordtype;
//    PROGTYPE progtype;
    T32U     urgency_prog_valid;
#if (TEXT_ROW_DISPLAY_SUPPORT > 0)
    T32U     op;
    T32U     busy;
    T32U     NewDataSize;
    T08U     NewData[536];
#endif
#if (NOISE_____AREA_MAX    > 0)
    T32U     HS5633T_noise_X_100;
#endif
#if (DYNAMIC___AREA_MAX > 0)
    T08U    dynamic[DYNAMIC___AREA_MAX][DYNAMIC_AREA_DATA_SIZE_MAX+4];
#endif
#if (AM2320____AREA_MAX > 0)
    T32U   AM2320Data;		/* according AM2320 manual,holding original huminity&temperature from AM2320 chip */
#endif    
#if (HeLiLaiXuanCaiHongSupport > 0)
    T32U  movestep;
#endif
#if (DYNAMIC_GB_AREA_MAX > 0)
    T08U    dynamicGB2312[DYNAMIC_GB_AREA_MAX][DYNAMIC_GB_DATA_SIZE_MAX+16];
#endif
}HWINFO;
/*
************************************************************************************************************************
*                                           globle varibles
************************************************************************************************************************
*/

extern COMMCFG    gCommCfg;
extern HWINFO     gInfo;
/*
************************************************************************************************************************
*                                           globle functions 
************************************************************************************************************************
*/

void globleInit (void);
void CRC16     (T08U *Message,T32U MsgLen,T08U *CRC16LoByte,T08U *CRC16HiByte);
/*
************************************************************************************************************************
*                                               end
************************************************************************************************************************
*/
#endif
